/**
 * 主表配置
 */
export const getOption = () => {
  return {
    height: 'auto',
    calcHeight: 30,
    tip: false,
    searchSpan: 5,
    searchShow: true,
    searchMenuSpan: 4,
    searchLabelWidth: 100,
    labelWidth: 120,
    menuWidth: 200,
    border: true,
    index: true,
    indexLabel: '序号',
    viewBtn: false,
    addBtn: false,
    delBtn: false,
    editBtn: false,
    selection: true,
    dialogClickModal: false,
    column: [
      {
        label: '产品编码',
        prop: 'partNo',
        search: true,
        searchLabelWidth: 80
      },
      {
        label: '产品名称',
        prop: 'partName',
        search: true
      },
      {
        label: '产品型号',
        prop: 'partModel',
        searchLabelWidth: 80
      },
      {
        label: '版本',
        prop: 'bomVersion',
        searchLabelWidth: 80,
        search: true
      },
      {
        label: '制定人',
        prop: 'creator'
      },
      {
        label: '制定日期',
        prop: 'sourceAduitDate'
      },
      {
        label: '生效日期',
        prop: 'sourceCreateDate'
      },
      {
        label: '状态',
        prop: 'status'
      }
    ]
  };
};
/**
 * 表单配置
 */
export const getPropertiesOption = (safe) => {
  return {
    submitText: '保存',
    menuPosition: 'right',
    labelWidth: 130,
    emptyBtn: false,
    submitBtn: true,
    column: [
      {
        label: '产品编码',
        prop: 'partNo',
        type: 'search',
        span: 7,
        disabled: true,
        cascader: ['partMasterId'],
        rules: [
          {
            required: true,
            message: '请输入选择产品编码',
            trigger: 'blur'
          }
        ],
        cascader: ['sourceBomId'],
        appendClick: () => {
          if (safe.title === '新增') {
            safe.openProductModal('PRODUCT');
          }
        }
      },
      {
        label: '产品名称',
        prop: 'partName',
        span: 7,
        disabled: true
      },
      {
        label: '基础BOM',
        prop: 'sourceBomId',
        type: 'select',
        span: 7,
        type: 'select',
        disabled: false,
        display: true,
        dicFlag: false,
        dicUrl: '/api/mes-admin/bom/detail/list/erp-bom-no-id?partNo={{key}}',
        props: {
          label: 'bomNo',
          value: 'sourceBomId'
        },
        cascader: ['bomVersion'],
        rules: [
          {
            required: true,
            message: '请输入选择版本号',
            trigger: 'blur'
          }
        ],
        dicFormatter: (data) => {
          return data.data;
        },
        change: (val) => {
          safe.sourceBomId = val.value;
        }
      },
      {
        label: '版本号',
        prop: 'bomVersion',
        dicUrl: '/api/mes-admin/bom/detail/list/erp-bom-no-id?bomId={{key}}',
        span: 7,
        dicFlag: false,
        disabled: true,
        rules: [
          {
            required: true,
            message: '请输入选择版本号',
            trigger: 'blur'
          }
        ],
        dicFormatter: (data) => {
          safe.properties['bomVersion'] = safe._get(data.data[0], 'bomVersion', '');
        }
      },
      {
        label: '制定人',
        prop: 'creator',
        span: 7,
        disabled: true,
        rules: [
          {
            required: true,
            message: '请输入选择指定人',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '制定日期',
        prop: 'createTime',
        type: 'datetime',
        span: 7,
        disabled: true,
        format: 'yyyy-MM-dd HH:mm:ss',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        rules: [
          {
            required: true,
            message: '请输入选择制定日期',
            trigger: 'blur'
          }
        ]
      }
    ]
  };
};
/**
 * 主物料清单配置
 */
export const getPartMasterOption = (safe) => {
  return {
    height: '200',
    labelWidth: 120,
    addBtn: false,
    selection: true,
    cellBtn: true,
    border: true,
    addRowBtn: false,
    index: true,
    indexLabel: '序号',
    menuWidth: 150,
    saveBtn: false,
    menu: false,
    refreshBtn: false,
    highlightCurrentRow: true, // 选中高亮
    column: [
      {
        label: '物料编码',
        prop: 'partNo',
        type: 'search',
        width: '200',
        cell: true,
        disabled: true,
        rules: [
          {
            required: true,
            message: '请输入物料编码',
            trigger: 'blur'
          }
        ],
        appendClick: () => {
          if (safe.title !== '查看') {
            safe.openKeyPartModal();
          }
        }
      },
      {
        label: '物料名称',
        prop: 'name'
      },
      {
        label: '物料类型',
        prop: 'partModel'
      },
      {
        label: '用量',
        prop: 'unitQty',
        type: 'number',
        precision: 0,
        minRows: '',
        width: 140,
        cell: true,
        rules: [
          {
            required: true,
            message: '请输入用量',
            trigger: 'blur'
          }
        ]
      },
      {
        label: '是否为关键料',
        prop: 'isKeyPart',
        type: 'select',
        value: false,
        cell: true,
        dicData: [
          {
            label: '是',
            value: true
          },
          {
            label: '否',
            value: false
          }
        ]
      }
    ]
  };
};

export const getReplacePartOption = (safe) => {
  return {
    height: '200',
    labelWidth: 120,
    index: true,
    indexLabel: '序号',
    addBtn: false,
    selection: true,
    cellBtn: true,
    border: true,
    addRowBtn: false,
    menuWidth: 150,
    menu: false,
    saveBtn: false,
    refreshBtn: false,
    column: [
      {
        label: '物料编码',
        prop: 'partNo',
        type: 'search',
        cell: true,
        width: '200',
        rules: [
          {
            required: true,
            message: '请输入物料编码',
            trigger: 'blur'
          }
        ],
        appendClick: () => {
          if (!safe.partId) {
            safe.$message({
              type: 'warning',
              message: '请先选择一条主料'
            });
            return;
          }
          if (safe.title !== '查看') {
            safe.openRepalcePartModal('replacePart');
          }
        }
      },
      {
        label: '物料名称',
        prop: 'partName'
      },
      {
        label: '物料类型',
        prop: 'partModel'
      },
      {
        label: '用量',
        prop: 'unitQty',
        type: 'number'
      },
      {
        label: '是否为关键料',
        prop: 'isKeyPart',
        type: 'select',
        value: false,
        dicData: [
          {
            label: '是',
            value: true
          },
          {
            label: '否',
            value: false
          }
        ]
      }
    ]
  };
};
